const app = getApp()
var { getMonthAndDay } = require("../../public/js/common.js");
var API = require('../../fetch/index.js');
const http = require('../../http/index');
const APICONSTE = require('../../http/apiConst');

function getDateList() {
  var list = [];
  for (var i = 1; i < 32; i++) {
    list.push(i);
  }
  return list;
}

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardNameVal:'',
    appNameVal:'',
    epaymetTimeVal: 1,
    billTimeVal: 1,
    remarksVal:'',
    dateList: getDateList()
  },

  //信用卡名
  addCardNameVal(event) {
    const cardNameVal = event.detail.value;
    this.setData({
      cardNameVal
    });
  },
  //相关APP名
  addAppNameVal(event) {
    const appNameVal = event.detail.value;
    this.setData({
      appNameVal
    });
  },
  //还款时间
  addEpaymetTimeVal(event) {
    const epaymetTimeVal = event.detail.value / 1 + 1;
    this.setData({
      epaymetTimeVal
    });
  },
  addBillTimeVal(event) {
    const billTimeVal = event.detail.value / 1 + 1;
    this.setData({
      billTimeVal
    });
  },
  //备注
  addRemarksVal(event) {
    const remarksVal = event.detail.value;
    this.setData({
      remarksVal
    });
  },

  /**
   * 保存信息
   */
  save:function () {
    var data = this.data;
    var saveData = {
      'card_name': data.cardNameVal,
      'app_name':data.appNameVal,
      'epaymet_time':data.epaymetTimeVal,
      'bill_time': data.billTimeVal,
      'remarks':data.remarksVal
    }
    http({
      action: APICONSTE.ADD_CREDAT,
      data: saveData
    }).then(data => {
      setTimeout(() => {
        wx.navigateBack();
      }, 300);
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})